package com.lanxigua.ui.master;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

import com.lanxigua.ui.Base;
import com.lanxigua.ui.R;
import com.lanxigua.ui.user.Login;

public class Splash extends Base {
	private Handler handler = new Handler();
	private ImageView imageview;
	int alpha = 255;
	int b = 0;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.hideTitle();

		imageview = (ImageView) this.findViewById(R.id.logo);

		imageview.setAlpha(alpha);
		new Thread(new Runnable() {
			public void run() {
				while (b < 2) {
					try {
						if (b == 0) {
							Thread.sleep(2000);
							b = 1;
						} else {
							Thread.sleep(3);
						}
						update();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				imageview.setAlpha(alpha);
				imageview.invalidate();
			}
		};
	}

	public void update() {
		alpha -= 1;
		if (alpha <= 0) {
			b = 2;
			Intent in = new Intent(Splash.this, Login.class);
			startActivity(in);
			finish();
			
		}
		handler.sendMessage(handler.obtainMessage());
	}
}